﻿using MediatR;
using SystemMHB.API.Application.Command.WarehouseCommand;
using SystemMHB.Domian.DTO;
using SystemMHB.Domian;
using SystemMHB.Infrstructer.Interface;

namespace SystemMHB.API.Application.CommandHandlers.WarehouseCommandHandler
{
    public class WarehouseListCommandHandler:IRequestHandler<WarehouseListCommand, PagingDTO<Warehouse>>
    {
        /// <summary>
        /// 仓库管理仓储
        /// </summary>
        IWarehouseRepository WarRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="WarRep">仓库管理仓储</param>
        public WarehouseListCommandHandler(IWarehouseRepository WarRep)
        {
            this.WarRep = WarRep;
        }

        public async Task<PagingDTO<Warehouse>> Handle(WarehouseListCommand request, CancellationToken cancellationToken)
        {
            var pageing = new PagingDTO<Warehouse>();
            var quest = from war in await WarRep.GetAllAsync() where war.IsDel ==  false select war;
            pageing.plist = quest.ToList();
            return pageing;
        }
    }
}
